<html>
<head>
<title>Insert Snippet</title>
<link rel="stylesheet" type="text/css" href="../../../popups/popup.css" />
<script type="text/javascript" src="../../../popups/popup.js"></script>
<script type="text/javascript">

var InsertSnippet = window.opener.InsertSnippet;
var editor = null;
var config;

function Init() {
  __dlg_translate("InsertSnippet");
  __dlg_init();
  
  var config = window.dialogArguments;
 
 eval(HTMLArea._geturlcontent(config.InsertSnippet.snippets));
  
  if (config.InsertSnippet.css.length > 0) 
  {
	  for (var i=0;i< config.InsertSnippet.css.length;i++)
	  {
  		var style = document.createElement("link");
	    style.rel = 'stylesheet';
	    style.href =  config.InsertSnippet.css[i];
	    document.getElementsByTagName("HEAD")[0].appendChild(style);
	  }
  }

  window.resizeTo(800, 600);
  window.moveTo(80, 80);
  var tbody = document.getElementById("snippettable");
  var snippet_html;
  var snippet_name;
  var trow;
  for(var i = 0; i < snippets.length; i++) 
  {
  	  trow = tbody.insertRow(i);
  	  snippet_html = snippets[i]['HTML'];
  	  snippet_name = snippets[i]['id'];
  	 
  	  var insertAsVariable = '';
  	  if (config.InsertSnippet.showInsertVariable)
  	  {
  	  	insertAsVariable = ' | <a href="javascript:onOK('+i+','+'\'variable\''+')">'+HTMLArea._lc("Variable","InsertSnippet")+'</a>';
  	  }
  	  var new_cell = trow.insertCell(0);
  	  new_cell.innerHTML = snippet_name +': '+HTMLArea._lc("Insert as","InsertSnippet")+' <a href="javascript:onOK('+i+','+'\'html\''+')">HTML</a>'+insertAsVariable + ' (<a id="show_preview'+i+'" href="javascript:preview(\'show\','+i+')">'+HTMLArea._lc("Show preview","InsertSnippet")+'</a>)<div id="preview'+i+'" style="display:none">'+snippets[i]['HTML']+'</div>'; 
  	  new_cell.id = 'cell' + i;
  	  
  }

  document.body.onkeypress = __dlg_key_press;
}

function preview(action,i) {
	var show_preview_link = document.getElementById('show_preview'+i); 
	switch(action)
	{
		case 'show':
			document.getElementById('preview'+i).style.display = 'block';
			show_preview_link.innerHTML = HTMLArea._lc("Hide preview","InsertSnippet");
			show_preview_link.href = "javascript:preview('hide','"+i+"');";
			
		break;
		case 'hide':
			document.getElementById('preview'+i).style.display = 'none';
			show_preview_link.innerHTML = HTMLArea._lc("Show preview","InsertSnippet");
			show_preview_link.href = "javascript:preview('show','"+i+"');";
		break;
	}
}
function onCancel() {
  __dlg_close(null);
  return false;
}

function onOK(snippetnum,how) {
  var params = new Object();
  params["snippetnum"] = snippetnum;
  params["how"] = how;
  __dlg_close(params);
  return false;
}

function __dlg_key_press(ev) {
  ev || (ev = window.event);
  switch(ev.keyCode) {
    case 13:
    document.getElementById('bt_ok').click();
      break;
    case 27:
    __dlg_close();
    return false;
  }
return true;
}
</script>

<style type="text/css">
body {margin:0 !IMPORTANT;padding:0 !IMPORTANT;}
.buttons {border-top: 1px solid #999; padding: 5px; text-align: right; height: 20px; }
td {background:white;padding:5px;border:1px solid;border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;}
.preview {}
</style>
</head>
  <body class="dialog" onload="Init()">
<form action="" method="get">
  <div class="title" >Insert Snippet</div>
  <div style="height:470px;overflow:auto;">
  <table style="border: 0; width: 100%;" id="snippettable">
  </table>
  </div>
<div class="space"></div>
<div class="buttons">
<button type="button" onclick="return onCancel();">Cancel</button>
</div>
</form>
</body>
</html>
